﻿using GalaSoft.MvvmLight;

namespace Budgetsch.WP7.ViewModel.Income
{
    using System;

    using Budgetsch.WP7.Navigation;
    using Budgetsch.WP7.WP7DataService;

    using GalaSoft.MvvmLight.Ioc;
    using GalaSoft.MvvmLight.Messaging;

    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class IncomeListDetailsViewModel : ViewModelBase
    {
        private readonly Income _income;
        private readonly INavigationService _navigationService;

        public decimal Amount
        {
            get
            {
                return _income.Amount;
            }
        }

        public bool IsRecurring
        {
            get
            {
                return _income.IsRecurring;
            }
        }

        public string IncomeCategoryName
        {
            get
            {
                return _income.IncomeCategory.Name;
            }
        }

        public string Description
        {
            get
            {
                return _income.Description;
            }
        }

        public bool IsCommented
        {
            get
            {
                return _income.IncomeComments.Count > 0;
            }
        }

        public IncomeListDetailsViewModel(Income income, INavigationService navigationService)
        {
            _income = income;
            _navigationService = navigationService;
        }

        public void NavigateToDetailsView()
        {
            SimpleIoc.Default.GetInstance<IncomeDetailsViewModel>();
            Messenger.Default.Send(new LoadIncomeDetailsViewMessage { Income = _income });
            SimpleIoc.Default.GetInstance<CommentWriterViewModel>();
            Messenger.Default.Send(new AddToUserNameMessage { UserName = _income.User.UserName});
            _navigationService.NavigateTo(new Uri("/View/IncomeDetailsView.xaml", UriKind.Relative));
        }
    }
}